package neusoft.edu.cn.mysanjixiangmu527hdl.model;

import neusoft.edu.cn.mysanjixiangmu527hdl.iface.RegisterListener;
import neusoft.edu.cn.mysanjixiangmu527hdl.service.RegisterService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.scalars.ScalarsConverterFactory;

/**
 * Created by Thinkpad on 2017/5/29.
 */

public class RegisterModel {
Retrofit retrofit;
    private static String BASEURL="http://amicool.neusoft.edu.cn";
    public RegisterModel() {
        retrofit=new Retrofit.Builder()
                .baseUrl(BASEURL)
                .addConverterFactory(ScalarsConverterFactory.create())
                .build();
    }
    public void register(String userName, String password, String tel, final RegisterListener listener)
    {
        RegisterService service =retrofit.create(RegisterService.class);
        Call<String> call=service.getReg(userName,password,tel);
        call.enqueue(new Callback<String >() {
            @Override
            public void onResponse(Call<String> call, Response<String> response) {
                if(response.body()!=null&&response.isSuccessful()){
                    listener.onResponse(response.body());

                }
                else{
                    System.out.println("==>>"+"response.onFail()");
                    listener.onFail("onResponse fail");
                }

            };

            @Override
            public void onFailure(Call<String> call, Throwable t) {
                listener.onFail(toString());
            }
        });
    }
}
